Auto-deref map access in assignments and Add Forward Declarations#14
Open
SiyuanSun0736 wants to merge 1 commit intomultikernel:mainfrom
Open
Auto-deref map access in assignments and Add Forward Declarations#14SiyuanSun0736 wants to merge 1 commit intomultikernel:mainfrom
SiyuanSun0736 wants to merge 1 commit intomultikernel:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR resolves a type mismatch bug in eBPF C code generation and improves the robustness of userspace code generation. The primary fix ensures that map lookups on the right-hand side of assignment statements follow KernelScript's value semantics rather than returning raw pointers.
Key Changes
1. eBPF C Codegen: Assignment Value Semantics
src/ebpf_c_codegen.mlgenerate_assignmentto useauto_deref_map_access:truewhen the source value is anIRMapAccess.var x = map[k]) correctly generated dereferencing logic, standard assignments (e.g.,x = map[k]) were incorrectly assigning thebpf_map_lookup_elempointer directly to a value-type variable.2. Userspace Codegen: Forward Declarations
src/userspace_codegen.mlint <handler>(<ValueType> *event);).dispatch_usedis true.Code Comparison (eBPF C)
Before
Assigning a pointer type (
struct Stats *) to a value type (struct Stats) caused a compilation error.After
The assignment now generates a safe dereferencing block with a NULL check.
Impact & Rationale
incompatible typeerror observed inexamples/ringbuf_demo.